//
//  TJHomeDetailHeaderView.m
//  Teleport
//
//  Created by hc-101 on 2020/6/16.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJHomeDetailHeaderView.h"

@interface TJHomeDetailHeaderView()

@property (weak, nonatomic) UILabel *availableValueLabel;
@property (weak, nonatomic) UILabel *freezeValueLabel;
@property (weak, nonatomic) UILabel *equivalentValueLabel;
@property (weak, nonatomic) UILabel *currencyNameLabel;
 

@end


@implementation TJHomeDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
            
        
        UIImageView *backgroundImageView = [[UIImageView alloc] init];
        [self addSubview:backgroundImageView];
        backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
        backgroundImageView.image = [UIImage imageNamed:@"omeDetailHeaderViewBg"];
        [backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.offset(0);
            make.bottom.offset(-40);
        }];
        
        UILabel *titleLabel = [UILabel lableWithSuperView:self font:MediumFont(15) color:UIColor_Hex(0x111111) title:@"财务记录".localizedString textAlignment:NSTextAlignmentLeft];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(16);
            make.bottom.offset(0);
            make.height.offset(40);
        }];
        
        UIView *lineView = [UIView tj_addToView:self];
        lineView.backgroundColor = UIColor.tj_separatorColor;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel);
            make.right.offset(-16);
            make.bottom.offset(0);
            make.height.offset(1);
        }];
        
        UIButton *screeningButton = [UIButton tj_addToView:self];
        [screeningButton setImage:[UIImage imageNamed:@"homeDetailScreening"] forState:UIControlStateNormal];
        [screeningButton setImage:[UIImage imageNamed:@"homeDetailScreening"] forState:UIControlStateHighlighted];
        [screeningButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(34);
            make.centerY.equalTo(titleLabel);
            make.right.offset(-6);
         }];
 
        UILabel *currencyNameLabel = [UILabel lableWithSuperView:backgroundImageView font:MediumFont(15) color:UIColor.whiteColor title:@"" textAlignment:NSTextAlignmentLeft];
                 [currencyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.top.offset(KNavBarHight);
                     make.left.offset(12);
                 }];
                 
                  UILabel *availableLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"可用".localizedString textAlignment:NSTextAlignmentLeft];
                 [availableLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                      make.top.equalTo(currencyNameLabel.mas_bottom).offset(14);
                      make.left.equalTo(currencyNameLabel);
                 }];
                 
                 
                 UILabel *availableValueLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"0.00000000" textAlignment:NSTextAlignmentLeft];
                 [availableValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.top.equalTo(availableLabel.mas_bottom).offset(4);
                     make.left.equalTo(availableLabel);
                 }];
              
                 UILabel *freezeLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"冻结".localizedString textAlignment:NSTextAlignmentLeft];
                 [freezeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.centerY.equalTo(availableLabel);
                     make.centerX.offset(0);
                 }];
                 
                 
                 UILabel *freezeValueLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"0.00000000" textAlignment:NSTextAlignmentLeft];
                 [freezeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.centerY.equalTo(availableValueLabel);
                     make.centerX.offset(0);
                 }];
                 
                 
                 UILabel *equivalentLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"折合(CNY)".localizedString textAlignment:NSTextAlignmentLeft];
                 [equivalentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.right.offset(-12);
                     make.centerY.equalTo(freezeLabel);
                 }];
                 
                 
                 UILabel *equivalentValueLabel = [UILabel lableWithSuperView:backgroundImageView font:UIFont_Px(14) color:UIColor.whiteColor title:@"0.00000000" textAlignment:NSTextAlignmentLeft];
                 [equivalentValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                     make.centerY.equalTo(freezeValueLabel);
                     make.right.equalTo(equivalentLabel);
                 }];
                 
                 _availableValueLabel = availableValueLabel;
                 _freezeValueLabel = freezeValueLabel;
                 _equivalentValueLabel = equivalentValueLabel;
                 _currencyNameLabel = currencyNameLabel;
        _screeningButton = screeningButton;
        
    }
    return self;
}


- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    
    _currencyNameLabel.text = [self currencyName];
    _availableValueLabel.text =  [Tools reviseString:[NSString stringWithFormat:@"%@", dict[@"balance"]]];
    _freezeValueLabel.text = [Tools reviseString:[NSString stringWithFormat:@"%@", dict[@"unbalance"]]];
    _equivalentValueLabel.text = [Tools reviseString:[NSString stringWithFormat:@"%@", dict[@"cny"]]];
}

- (NSString *)currencyName {
    int coinNo = [_dict[@"coinNo"] intValue];
    if (coinNo == 1) return @"BTC";
    if (coinNo == 2) return @"USDT";
     return @"";
}

@end
